<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html; charset=big5" language="java" import="util.*, java.sql.*,beans.*" errorPage="" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Floated=3col</title>
<link href="astyles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="absolute_title">Captain Hook's Store</div>
<div class="absolute_title2"> 
  <h5>
  <%
  String username = (String)session.getAttribute("username");
                    
   if(username==null) {
      out.println("Please <a href='login.jsp'>Login.</a>");
      }else {
    %>
	
  <h5>Hi!<%= username%><br/>
    <a href="logout.jsp"> Click here to logout</a></h5>
  <% }
                %></h5>
</div>

<div class="wrap">
  <div class="canvas">
    <div class="left_column">
      <div class="header_left">
        <div class="header_leftrowone">&nbsp;</div>
        <div class="header_leftrowtwo"><img src="../image/cpt_hook_banner1.jpg" width="123" height="87" /></div>
        <div class="header_leftrowthree"></div>
      </div>
      <div class="leftnav">
        <ul>
          <li></li>
        </ul>
      </div>
      <div>
        <SCRIPT src="displayMyFlash1.js"></SCRIPT>
      </div>
    </div>
    <div class="right_column">
      <div class="header_right">
        <div class="header_rightrowone">&nbsp;</div>
        <div class="header_rightrowtwo">&nbsp;</div>
        <div class="header_rightrowthree">
          <ul class="topmenu">
            <li><a title="Home" 
  href="index.jsp">Home</a> | </li>
            <li><a title="Information" 
  href="companybackground.html">Information</a> |
            <li><a title="Forum" 
  href="http://www.voy.com/206926/">Discussion Forum</a></li>
          </ul>
        </div>
      </div>
      <div class="content_wrapper">
        <div class="content_left">
		
		<div>
		<form action='SearchServlet' method='get'>
            Enter keyword to search:
            <input type='text' name='keyword'/>
            <input name='submit' type='submit' value='Search' />
            <a href="AdvanceSearch.jsp">Advanced search</a>
          </form>
		  
		  </div>
          <h2>Catalogue Page</h2>
          <table width="130%" height="100%" border="1">
            <tr bgcolor="white">
              <td width="49"><b>Item ID:</b></td>
              <td width="40"><b>Name</b></td>
              <td width="40"><b>Type</b></td>
              <td width="54"><b>Company</b></td>
              <td width="40"><b>Scale</b></td>
              <td width="46"><b>Price</b></td>
              <td width="177"><b>Image (Click to view its details)</b></td>
              <td width="49"><b>Quantity</b></td>
              <td width="47"><b>Buy</b></td>
            </tr>
            <%
                            
                            
                            final String sPage = (String)request.getParameter("page");
                            int page1 = 0; //<====
                            final int recordPerPage = 5;
                            final int indexPerPage =10;
                            final int count = ModelBean.getTotalRecordCount(); //<=======
                            final int indexCount = (int)Math.floor(count / (double)recordPerPage);
                            if(page1 > indexCount) {
                                page1 = 0;
                            }
                            if(util.Utilities.isValid(sPage)) {
                                try {
                                    page1 = Integer.parseInt(sPage);
                                } catch(Exception e) {
                                    
                                }
                            }
                            final int k=page1;
                            
                            
                            %>
            <%
                            
                            try {
                                ModelBean[] models = ModelBean.getAllModel();
                                for(int z=recordPerPage*page1; z<(page1+1)*recordPerPage; z++ ) {
                                    
                                    String itemId = models[z].getItemID();
                                    String name = models[z].getName();
                                    String type = models[z].getType();
                                    String company = models[z].getCompany();
                                    String scale = models[z].getScale();
                                    String price = models[z].getPrice();
                                    String description = models[z].getDescription();
                                    String imageURL = models[z].getImageURL();
                            %>
            <form action='SavecartServlet' method='get'>
              <tr>
                <td><%=itemId%>
                  <input type='hidden' name='itemID' value='<%=itemId%>' />
                </td>
                <td><%=name%>
                  <input type='hidden' name='name' value='<%=name%>' />
                </td>
                <td><%=type%>
                  <input type='hidden' name='type' value='<%=type%>' />
                </td>
                <td><%=company%>
                  <input type='hidden' name='company' value='<%=company%>' />
                </td>
                <td><%=scale%>
                  <input type='hidden' name='scale' value='<%=scale%>' />
                </td>
                <td> $<%=price%>
                  <input type='hidden' name='price' value='<%=price%>' />
                </td>
                <td><a href='ItemDetail.jsp?imageURL=<%=imageURL%>'><img src='../image/<%=imageURL%>' width="162" height="200" border="0"/></a>
                  <input type='hidden' name='imageURL' value='<%=imageURL%>' />
                </td>
                <td><input type='text' size='5' name='quantity' value='1' />
                </td>
                <td valign='top'><input name="submit2" type='submit' value='Buy' />
                </td>
              </tr>
            </form>
            <%
                                }
                            } catch(Exception e) {
                                e.printStackTrace();
                            }
                            %>
            <%!                                
                            void printIndex(int k, int i, JspWriter out1) {
                                try {
                                    if (i==k) {
                                        out1.println("<b><a href='Catalogue.jsp?page="+i+"'>"+(i+1)+"</a></b>");
                                    }else {
                                        out1.println("<a href='Catalogue.jsp?page="+i+"'>"+(i+1)+"</a>");
                                    }
                                }catch(Exception e) {
                                    
                                }
                            }
                            
                            %>
          </table>
          <p>&nbsp;</p>
          <div class="post_btm">
            <form method='get' action='Catalogue.jsp'>
              <center>
                <%
                                int nextValue = 5;
                                int remain = count-(indexCount+page1);
                                if (remain < indexPerPage) {
                                    nextValue = remain % indexPerPage;
                                }
                                if(k < 5) {
                                    for(int i=0; i<=indexCount&&i<indexPerPage; i++) {
                                        printIndex(k, i, out);
                                    }
                                }else if(k >= indexCount-indexCount%indexPerPage -1) {
                                    int start = indexCount - indexPerPage;
                                    for(int y=0; y <indexPerPage; y++) {
                                        printIndex(k, y+start, out);
                                    }
                                }else {
                                    for (int i=0; i<5; i++) {
                                        printIndex(k, page1-5+i, out);
                                    }
                                    for (int i=0; i< 5&& page1+i<indexCount; i++) {
                                        printIndex(k, page1+i, out);
                                    }
                                }
                                %>
                <input type='hidden' name='page' value='<%= k+1%>' />
                <input name="submit" type = "submit" value='Next Page'/>
              </center>
            </form>
          </div>
        </div>
      </div>
      <div class="footer">
        <ul class="basemenu">
          <li></li>
        </ul>
        Designed by Captain Hook inc, all rights reserved. <br />
      </div>
    </div>
  </div>
</div>
<!-- Begin Image Preload (hiddenpics) -->
<img src="media/arrowblack_left.gif" 
  alt="hiddenpic"  
    height="350" width="350" class="hiddenpic" /> <img src="media/arrowwhite_left.gif" 
  alt="hiddenpic" 
    height="350" width="350" class="hiddenpic" /> <img src="media/dualarrowgold.gif"
  alt="hiddenpic" 
     height="350" width="350" class="hiddenpic" /><img src="media/brush.gif"
  alt="hiddenpic"
     height="350" width="350" class="hiddenpic" /> <img src="media/camera1.jpg" 
  alt="hiddenpic"
     height="350" width="350" class="hiddenpic" /> <img src="media/camera2.jpg" 
  alt="hiddenpic" 
     height="350" width="350" class="hiddenpic" /> <img src="media/camera3.jpg" 
  alt="hiddenpic" 
     height="350" width="350" class="hiddenpic" /> <img src="media/ebay.gif" 
  alt="hiddenpic" 
    height="350" width="350" class="hiddenpic" /> <img src="media/brush.gif"
  alt="hiddenpic"
     height="350" width="350" class="hiddenpic" /> <img src="media/shadow_leftontaupe.jpg" 
  alt="hiddenpic"
     height="350" width="350" class="hiddenpic" /> <img src="media/shadow_rightontaupe.jpg" 
  alt="hiddenpic" 
     height="350" width="350" class="hiddenpic" />
<!-- Begin Image Preload (hiddenpics) -->
</body>
</html>
